--[[
Author: your name
Date: 2020-12-01 11:04:21
LastEditTime: 2020-12-01 20:33:58
LastEditors: your name
Description: In User Settings Edit
FilePath: \Lua\View\CharactorUI\UICharactorAttributeDetailsItem.lua
--]]
require "Common/define"
require "Logic/Config"
require "Common/functions"

UICharactorAttributeDetailsItem = {};
HelperFunc.SetUIEnv(UICharactorAttributeDetailsItem)
local this = UICharactorAttributeDetailsItem;
this.transform = nil;
this.LuaBehaviour = nil;

this.txtAttrName = nil;
this.txtAttrValue = nil;
this.imgAttr = nil;

function UICharactorAttributeDetailsItem.Init()
    local name,package = getUIName(PanelNames.UICharactorAttributeDetailsItem);
    panelMgr:ShowUI(name,package, this.onCreate,Config.useLocalUI);
end

function UICharactorAttributeDetailsItem.onCreate(obj)
    obj:SetActive(false);
end
---@param obj FairyGUI.GComponent
function UICharactorAttributeDetailsItem.initData(obj,data,luaBehaviour)
    --LuaBehaviour = luaBehaviour;
    --gameObject = obj;
    --transform = obj.transform;

    local strKey = data.name;
    local intVal = Mathf.Round(data.value);
    local attributeType = data.type;
    local iconName = data.icon;
    txtAttrName = obj:GetChild("AttrName")
    txtAttrValue = obj:GetChild("AttrValue")
    imgAttr = obj:GetChild("AttrIcon")

    txtAttrName.text = strKey;
    if attributeType==2 then
        txtAttrValue.text = (intVal/100).."%";
    else
        txtAttrValue.text =intVal;
    end
    imgAttr.url = "ui://ICONAtlas/"..iconName
    --resMgr:LoadIconFromPrefab("ICONAtlas",iconName,function (sp)
    --    imgAttr.sprite = sp;
    --end);
    
end

return UICharactorAttributeDetailsItem;